//
//  YMMedicalUtil.m
//  YMMedical
//
//  Created by y s on 2023/6/19.
//

#import "YMMedicalUtil.h"
#import "UIApplication+Helper.h"
#import "YMMyModel.h"
#import "YMAliYunUtil.h"
#import <Bugly/Bugly.h>
#import <AFNetworkReachabilityManager.h>
#import "YMLanguageUtil.h"


@interface YMMedicalUtil()<BuglyDelegate>


@end


@implementation YMMedicalUtil

+ (instancetype)shared{
   static dispatch_once_t onceToken;
   static YMMedicalUtil *sharedInstance;
   dispatch_once(&onceToken, ^{
       sharedInstance = [[YMMedicalUtil alloc] init];
   });
   return sharedInstance;
}

- (instancetype)init{
   if (self = [super init]){
       
   }
   return self;
}


#pragma mark -- public methods
// 启动
- (void)launch:(NSDictionary *)launchOptions{
    [[[NSThread currentThread] threadDictionary] setValue:[[MyAssertHandler alloc] init] forKey:NSAssertionHandlerKey];
    [[YMLanguageUtil shared] launch];
    [YMSafeUtil shared].block = ^(NSString *name, NSString *reason, NSString *place) {
       NSLog(@"! SSafeKit日志:\n! 异常名称:%@\n! 异常原因:%@\n! 异常位置:%@",name,reason,place);
    };
    [UIApplication setupAppearance];
    [YMSafeUtil fixed];
   
//    [self initBugly];
    [SNetUtil launch];
    [[YMMyModel shared] launch];
    [[YMAliYunUtil shared] aliyunLaunch];
    [self reachabilityAction];
}

// 初始化Bugly
- (void)initBugly{
    BuglyConfig *config = [[BuglyConfig alloc] init];
    // 非正常退出事件
    config.unexpectedTerminatingDetectionEnable = YES;
#if DEBUG
    // 开启SDK与补丁日志
    config.debugMode = YES;
#endif
    // 卡顿监控
    config.blockMonitorEnable = YES;
    // 进程内还原符号
    config.symbolicateInProcessEnable = YES;
    // 自定义渠道标识
    config.channel = @"AppStore";
    // 自定义版本号
    config.version = [SAppUtil shortVersion];
    // 控制台日志上报开关
    config.consolelogEnable = YES;
    config.reportLogLevel = BuglyLogLevelInfo;
    config.delegate = self;
    [Bugly startWithAppId:bugly_appId_key config:config];
}


- (void)reachabilityAction{
    //开启监听，记得开启，不然不走block
    AFNetworkReachabilityManager *reachabilityManger = [AFNetworkReachabilityManager sharedManager];
    [reachabilityManger startMonitoring];
    //2.监听改变
    [reachabilityManger setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络");
                break;
            case AFNetworkReachabilityStatusNotReachable:
                [SHUD showInfo:@"网络已断开,请检查网络"];
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"3G|4G");
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WiFi");
                break;
            default:
                break;
        }
    }];
}


@end
